﻿namespace ExamV5.OnLineInter
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class ShowForumInfo : Page
    {
        protected Button butAdd;
        protected Button butDefault;
        protected Button butDel;
        protected Button butReturn;
        protected Button butSetTop;
        protected Button butUnTop;
        protected CheckBox CheckAnony;
        protected GridView DataGridInfo;
        protected GridView DataGridRestore;
        protected DropDownList DDLJumpForum;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private HttpCookie httpCookie_4 = null;
        private int int_0 = 0;
        protected int intTypeID = 0;
        protected Label labBKInfo;
        protected Label labEidtID;
        protected Label Label1;
        protected Label Label2;
        protected Label labManagForum;
        protected Label labRescordCount;
        protected Label labTip;
        protected Label labTitleWTip;
        protected Label labWriteWTip;
        protected LinkButton LBFirstPage;
        protected LinkButton LBLastPage;
        protected LinkButton LBNextPage;
        protected LinkButton LBPrevPage;
        private PublicFun publicFun_0 = new PublicFun();
        protected HtmlInputHidden txtRestoreContent;
        protected TextBox txtRestoreTitle;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string str3;
            SqlConnection connection;
            SqlCommand command;
            string str = "";
            if (!this.CheckAnony.Checked)
            {
                str = this.httpCookie_1.Value;
            }
            else
            {
                str = "匿名发表";
            }
            string str5 = "";
            if (!(this.httpCookie_4.Value == "女"))
            {
                str5 = "../image/boy.gif";
            }
            else
            {
                str5 = "../image/gril.gif";
            }
            if (this.labEidtID.Text == "0")
            {
                str3 = "insert into ForumList(TitleInfo,ContentInfo,ReadNum,UserImg,InputUser,TypeID,UPID,Flag) values(@TitleInfo,@ContentInfo,@ReadNum,@UserImg,@InputUser,@TypeID,@UPID,@Flag)";
                connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                connection.Open();
                command = new SqlCommand(str3, connection);
                command.Parameters.Add("@ContentInfo", SqlDbType.Text).Value = this.txtRestoreContent.Value;
                command.Parameters.Add("@TitleInfo", SqlDbType.VarChar, 100).Value = this.publicFun_0.CheckString(this.txtRestoreTitle.Text);
                command.Parameters.Add("@ReadNum", SqlDbType.Int).Value = 0;
                command.Parameters.Add("@UserImg", SqlDbType.VarChar, 50).Value = str5;
                command.Parameters.Add("@InputUser", SqlDbType.VarChar, 20).Value = str;
                command.Parameters.Add("@TypeID", SqlDbType.Int).Value = 0;
                command.Parameters.Add("@UPID", SqlDbType.Int).Value = this.int_0;
                command.Parameters.Add("@Flag", SqlDbType.Char, 1).Value = "A";
                command.ExecuteNonQuery();
                command.Dispose();
                connection.Close();
                connection.Dispose();
                if (this.publicFun_0.GetValues(string.Concat(new object[] { "select ID from UserStudyFen where UserCode='", this.httpCookie_0.Value, "' and Formtable='ForumList' and FormID=", this.int_0 }), "ID") == "")
                {
                    string values = this.publicFun_0.GetValues("select ReFen from ForumType where ID=" + this.intTypeID, "ReFen");
                    this.publicFun_0.ExecuteSql(string.Concat(new object[] { "insert into UserStudyFen(UserCode,ExamStudyName,StudyFen,Formtable,FormID,ExamOrStudy) values('", this.httpCookie_0.Value, "','", this.publicFun_0.CheckString(this.txtRestoreTitle.Text), "','", values, "','ForumList','", this.int_0, "','F')" }));
                }
                this.publicFun_0.ExecuteSql(string.Concat(new object[] { "update ForumList set updateUser='", str, "',updateTime=getdate() where ID=", this.int_0 }));
            }
            else
            {
                str3 = "update ForumList set TitleInfo=@TitleInfo,ContentInfo=@ContentInfo where ID=" + this.labEidtID.Text;
                connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                connection.Open();
                command = new SqlCommand(str3, connection);
                command.Parameters.Add("@ContentInfo", SqlDbType.Text).Value = this.txtRestoreContent.Value;
                command.Parameters.Add("@TitleInfo", SqlDbType.VarChar, 100).Value = this.txtRestoreTitle.Text;
                command.ExecuteNonQuery();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
            this.labEidtID.Text = "0";
            this.txtRestoreTitle.Text = "";
            this.txtRestoreContent.Value = "";
            this.method_0();
        }

        protected void butDel_Click(object sender, EventArgs e)
        {
            this.publicFun_0.ExecuteSql(string.Concat(new object[] { "Delete from  ForumList where ID=", this.int_0, ";delete from ForumList where UPID=", this.int_0 }));
            string str = base.Request.Url.ToString();
            str = str.Substring(0, str.LastIndexOf('/') + 1);
            base.Response.Redirect(str + "ListForumInfo.aspx?TypeID=" + this.intTypeID);
        }

        protected void butReturn_Click(object sender, EventArgs e)
        {
            string str = base.Request.Url.ToString();
            str = str.Substring(0, str.LastIndexOf('/') + 1);
            base.Response.Redirect(str + "ListForumInfo.aspx?TypeID=" + this.intTypeID);
        }

        protected void butSetTop_Click(object sender, EventArgs e)
        {
            this.publicFun_0.ExecuteSql("UpDate ForumList set Flag='T' where ID=" + this.int_0);
            base.Response.Write("<script>alert('置顶操作成功！');window.opener.location.reload();</script>");
        }

        protected void butUnTop_Click(object sender, EventArgs e)
        {
            this.publicFun_0.ExecuteSql("UpDate ForumList set Flag='A' where ID=" + this.int_0);
            base.Response.Write("<script>alert('取消置顶操作成功！');window.opener.location.reload();</script>");
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton button = (LinkButton) e.Row.FindControl("LBEditMain");
                Label label = (Label) e.Row.FindControl("labDelMain");
                Label label2 = (Label) e.Row.FindControl("labMainID");
                Label label3 = (Label) e.Row.FindControl("labUserForum");
                if (label3.Text.Trim() == this.httpCookie_1.Value)
                {
                    button.Visible = true;
                    label.Visible = true;
                    label.Attributes.Add("onclick", "javascript:{if(confirm('确定要删除吗？')==false) return false;}");
                    label.Text = string.Concat(new object[] { "<a href='DelForumInfo.aspx?TypeID=", this.intTypeID, "&ID=", label2.Text, "'>删除</a>" });
                }
                else
                {
                    button.Visible = false;
                    label.Visible = false;
                }
            }
        }

        protected void DataGridInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Label label = (Label) this.DataGridInfo.Rows[e.RowIndex].FindControl("labTitleForum");
            Label label2 = (Label) this.DataGridInfo.Rows[e.RowIndex].FindControl("labContentForum");
            Label label3 = (Label) this.DataGridInfo.Rows[e.RowIndex].FindControl("labMainID");
            this.labEidtID.Text = label3.Text;
            this.txtRestoreTitle.Text = label.Text;
            this.txtRestoreContent.Value = label2.Text;
        }

        protected void DataGridRestore_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridRestore.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridRestore_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex != -1)
            {
                e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
                if ((e.Row.DataItemIndex % 2) == 0)
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
                }
                else
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
                }
            }
            else
            {
                this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
                this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
            }
        }

        protected void DataGridRestore_RowDataBound1(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label label3 = (Label) e.Row.FindControl("labUserRestore");
                LinkButton button = (LinkButton) e.Row.FindControl("LBEditChild");
                Label label = (Label) e.Row.FindControl("labDelChild");
                Label label2 = (Label) e.Row.FindControl("labChildID");
                if (label3.Text.Trim() == this.httpCookie_1.Value)
                {
                    button.Visible = true;
                    label.Visible = true;
                    label.Attributes.Add("onclick", "javascript:{if(confirm('确定要删除吗？')==false) return false;}");
                    label.Text = string.Concat(new object[] { "<a href='DelForumInfo.aspx?TypeID=", this.intTypeID, "&ID=", label2.Text, "'>删除</a>" });
                }
                else
                {
                    button.Visible = false;
                    label.Visible = false;
                }
            }
        }

        protected void DataGridRestore_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Label label = (Label) this.DataGridRestore.Rows[e.RowIndex].FindControl("labTitleRestore");
            Label label2 = (Label) this.DataGridRestore.Rows[e.RowIndex].FindControl("labContentRestore");
            Label label3 = (Label) this.DataGridRestore.Rows[e.RowIndex].FindControl("labChildID");
            this.labEidtID.Text = label3.Text;
            this.txtRestoreTitle.Text = label.Text;
            this.txtRestoreContent.Value = label2.Text;
        }

        protected void DDLJumpForum_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.DDLJumpForum.SelectedItem.Value != "0")
            {
                string str = base.Request.Url.ToString();
                str = str.Substring(0, str.LastIndexOf('/') + 1);
                base.Response.Redirect(str + "ListForumInfo.aspx?TypeID=" + this.DDLJumpForum.SelectedItem.Value);
            }
        }

        protected void LBFirstPage_Click(object sender, EventArgs e)
        {
            this.DataGridRestore.PageIndex = 0;
            this.method_0();
        }

        protected void LBLastPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageCount > 0)
            {
                this.DataGridRestore.PageIndex = this.DataGridRestore.PageCount - 1;
                this.method_0();
            }
        }

        protected void LBNextPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridRestore.PageIndex < (this.DataGridRestore.PageCount - 1))
            {
                this.DataGridRestore.PageIndex++;
                this.method_0();
            }
        }

        protected void LBPrevPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridRestore.PageIndex > 0)
            {
                this.DataGridRestore.PageIndex--;
                this.method_0();
            }
        }

        private void method_0()
        {
            string selectCommandText = "";
            selectCommandText = "select * from ForumList where UPID=" + this.int_0;
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridRestore.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridRestore.DataBind();
            this.labRescordCount.Text = "总共&nbsp;<font color='#0000C0'><b>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</b></font>&nbsp;条记录&nbsp;<font color='#0000C0'><b>" + Convert.ToString((int) (this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b></font>&nbsp;页&nbsp;";
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            this.httpCookie_4 = new HttpCookie("ExamUserSex");
            this.httpCookie_4 = base.Request.Cookies["ExamUserSex"];
            this.intTypeID = Convert.ToInt32(base.Request["UPID"]);
            this.int_0 = Convert.ToInt32(base.Request["ID"]);
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.httpCookie_4.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_4.Value));
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---查看论坛帖子信息";
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                    else
                    {
                        if (this.httpCookie_2.Value == "A")
                        {
                            this.labManagForum.Visible = false;
                        }
                        this.labTip.Text = "<b><font color=red>论坛公告：</font></b>";
                        this.DDLJumpForum.DataTextField = "TypeName";
                        this.DDLJumpForum.DataValueField = "ID";
                        this.DDLJumpForum.DataSource = this.publicFun_0.RetrunDataView("select ID,TypeName from ForumType order by ID ");
                        this.DDLJumpForum.DataBind();
                        this.DDLJumpForum.Items.Insert(0, new ListItem("跳转论坛至......", "0"));
                        this.ViewState["ManagPower"] = this.publicFun_0.GetValues("select ManagForum from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ManagForum");
                        string str = "";
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select IsAnony,Manager,TypeName,TipInfo from ForumType where  ID=" + this.intTypeID, connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.labBKInfo.Text = this.labBKInfo.Text + "→" + reader["TypeName"].ToString();
                            this.labTip.Text = this.labTip.Text + reader["TipInfo"].ToString();
                            if (!(reader["IsAnony"].ToString() == "Y"))
                            {
                                this.CheckAnony.Enabled = false;
                            }
                            else
                            {
                                this.CheckAnony.Enabled = true;
                            }
                            str = reader["Manager"].ToString();
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        if (this.publicFun_0.ExecuteSql("update ForumList set ReadNum=ReadNum+1 where ID=" + this.int_0) == 0)
                        {
                            base.Response.Write("<script>alert('此帖子已删除！')</script>");
                            this.Page.Response.Write("<script>setTimeout(function(){window.location='ListForumInfo.aspx?TypeID=" + this.intTypeID + "'},500)</script>");
                        }
                        if (!(this.ViewState["ManagPower"].ToString() == "N") || !(str.Trim() != this.httpCookie_0.Value))
                        {
                            this.butSetTop.Visible = true;
                            this.butUnTop.Visible = true;
                            this.butDel.Visible = true;
                        }
                        else
                        {
                            this.butSetTop.Visible = false;
                            this.butUnTop.Visible = false;
                            this.butDel.Visible = false;
                        }
                        this.butSetTop.Attributes.Add("onclick", "javascript:{if(confirm('确定将此帖子设置置顶？')==false) return false;}");
                        this.butUnTop.Attributes.Add("onclick", "javascript:{if(confirm('确定将取消此帖子置顶？')==false) return false;}");
                        this.butDel.Attributes.Add("onclick", "javascript:{if(confirm('确定删除此帖子信息吗？')==false) return false;}");
                        this.DataGridInfo.DataSource = this.publicFun_0.RetrunDataView("select * from ForumList where ID=" + this.int_0);
                        this.DataGridInfo.DataBind();
                        this.method_0();
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

